package org.brownflat.lighthouse.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

/**
 * <p>&copy Rupert Jones 2012</p>
 *
 * @author rup
 */
public class StringUtil {

    public static String toString(InputStream is) {
        final char[] buffer = new char[0x10000];
        StringBuilder out = new StringBuilder();

        int read;
        do {
            try {
                Reader in = new InputStreamReader(is, "UTF-8");
                read = in.read(buffer, 0, buffer.length);
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }

            if (read>0) {
                out.append(buffer, 0, read);
            }
        } while (read>=0);
        return out.toString();
    }

}
